/* eslint-disable no-redeclare */
import { Base64 } from "js-base64";
import CryptoJS from "crypto-js";

function getDES(password) {
    //加密
    var key = "97498121231284655fsafasa"; //密钥
    var iv = "kfao5417";
    var encrypted = getDesString(password, key, iv); //密文
    return Base64.encode(encrypted);
}

function getDesString(data, key, iv) {
    //加密
    var C_key = CryptoJS.enc.Utf8.parse(key);
    var C_iv = CryptoJS.enc.Utf8.parse(iv);
    var encrypted = CryptoJS.DES.encrypt(data, C_key, {
        iv: C_iv, //向量  偏移量
        mode: CryptoJS.mode.CBC, //加密模式
        padding: CryptoJS.pad.Pkcs7 //填充模式 补位
    });
    return encrypted.toString(); //返回的是base64格式密文
}

// 年级数组显示
function getStage(type) {
    var Stage = [
        [
            {
                grade: 1,
                grade_name: "一年级"
            },
            {
                grade: 2,
                grade_name: "二年级"
            },
            {
                grade: 3,
                grade_name: "三年级"
            },
            {
                grade: 4,
                grade_name: "四年级"
            },
            {
                grade: 5,
                grade_name: "五年级"
            },
            {
                grade: 6,
                grade_name: "六年级"
            }
        ],
        [
            {
                grade: 7,
                grade_name: "七年级"
            },
            {
                grade: 8,
                grade_name: "八年级"
            },
            {
                grade: 9,
                grade_name: "九年级"
            }
        ],
        [
            {
                grade: 10,
                grade_name: "高一"
            },
            {
                grade: 11,
                grade_name: "高二"
            },
            {
                grade: 12,
                grade_name: "高三"
            }
        ]
    ];
    if (type == 999) {
        //不分阶段为一组，带名称和ID
        var arr = [];
        for (var i = 0; i < Stage.length; i++) {
            for (var j = 0; j < Stage[i].length; j++) {
                arr.push(Stage[i][j]);
            }
        }
        return arr;
    } else if (type == 998) {
        //根据阶段分三组，带名称和ID，插入全部
        for (var i = 0; i < Stage.length; i++) {
            Stage[i].unshift({
                grade: "",
                grade_name: "全部年级"
            });
        }
        return Stage;
    } else if (type == 997) {
        //不分阶段为一组，带名称
        var arr = [];
        for (var i = 0; i < Stage.length; i++) {
            for (var j = 0; j < Stage[i].length; j++) {
                arr.push(Stage[i][j].grade_name);
            }
        }
        return arr;
    } else if (type == 996) {
        //根据阶段分三组，带名称
        var arr = [];
        for (var i = 0; i < Stage.length; i++) {
            arr[i] = [];
            for (var j = 0; j < Stage[i].length; j++) {
                arr[i].push(Stage[i][j].grade_name);
            }
        }
        return arr;
    } else if (type == 995) {
        //根据阶段分三组，带ID
        var arr = [];
        for (var i = 0; i < Stage.length; i++) {
            arr[i] = [];
            for (var j = 0; j < Stage[i].length; j++) {
                arr[i].push(Stage[i][j].grade);
            }
        }
        return arr;
    } else {
        //根据阶段分三组，带名称和ID
        return Stage;
    }
}

// 年级显示
function getgradeName(id) {
    var gradeName = "";
    switch (id) {
        case 1:
            gradeName = "一年级";
            break;
        case 2:
            gradeName = "二年级";
            break;
        case 3:
            gradeName = "三年级";
            break;
        case 4:
            gradeName = "四年级";
            break;
        case 5:
            gradeName = "五年级";
            break;
        case 6:
            gradeName = "六年级";
            break;
        case 7:
            gradeName = "七年级";
            break;
        case 8:
            gradeName = "八年级";
            break;
        case 9:
            gradeName = "九年级";
            break;
        case 10:
            gradeName = "高一";
            break;
        case 11:
            gradeName = "高二";
            break;
        case 12:
            gradeName = "高三";
            break;
        default:
            gradeName = "全部";
            break;
    }
    return gradeName;
}
// 类型显示
function getKindName(type) {
    /* 根据test_type显示对应的名称 */
    if (type == "zice") {
        return "自评";
    } else if (type == "mokao") {
        return "模考";
    } else if (type == "yuekao") {
        return "月考";
    } else if (type == "qizhong") {
        return "期中";
    } else if (type == "qimo") {
        return "期末";
    } else if (type == "zhenti") {
        return "真题";
    } else if (type == "gufen") {
        return "估分";
    } else if (type == "yati") {
        return "押题";
    } else if (type == "wenzong") {
        return "文综";
    } else if (type == "lizong") {
        return "理综";
    } else if (type == "danyuan") {
        return "单元";
    } else if (type == "zhice") {
        return "智测";
    } else if (type == "kaochang") {
        return "考场";
    }
}

export default {
    getDES: getDES,
    getStage: getStage,
    getgradeName,
    getKindName
};
